<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/12/2 0002
 * Time: 15:17
 */

namespace app\admin\controller;

use app\admin\model\Depart;
use think\Controller;
use think\Db;
use think\Session;
use app\admin\model\Emp;
use app\admin\model\Admin;

class login extends Controller
{

    public function index()
    {
        return $this->fetch();
    }

    public function login($username, $password)
    {
        $user = Db::name('admin')->where('Aname', $username)->find();
        if (empty($user)) {
            $this->error('用户不存在');
        }
        if ($user['Apassword'] == $password) {
            Session::set('username', $username);
            $this->success('登陆成功', 'houtai/index');

        } else {
            $this->error('密码错误');
        }
    }

    public function register()
    {
        return $this->fetch();

    }

    public function doreg()
    {

        $data = $this->request->param();
        $model = new Admin();
        $res = $model->save($data);
        if ($res) {
            $this->success('注册成功', 'login/index');
        } else {
            $this->error('注册失败');
        }
    }

    public function logout()
    {
        session(null);
        $this->success('退出成功', 'login/index');
    }

}
